const { resolve } = require('path')

const ejs = require('ejs')

const compileEjs = (template, data) => {
  const ejsComplatesContext = resolve(__dirname, '../ejs-templates')
  const complateAbsolutePath = resolve(ejsComplatesContext, template)

  return new Promise((resolve, reject) => {
    ejs.renderFile(complateAbsolutePath, { data }, {}, (err, result) => {
      if (err) {
        reject(err)
        return
      } else {
        resolve(result)
      }
    })
  })
}

module.exports = {
  compileEjs
}
